-
Notifications
You must be signed in to change notification settings - Fork 167
Refactor + separately test the instance deletion logic in task scheduling #9097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
e0e8250 to
3de24fd
Compare
|
PTAL: I've updated the code as we've discussed - removed the events, fixed the logic (old test pass), and using a full list of instances. |
3de24fd to
135b26b
Compare
|
|
||
| return DeleteInstancesNextState( | ||
| state: DeleteInstancesState(deletions: deletionInProgress), | ||
| deletionsDone: futures.isEmpty ? Future.value() : Future.wait(futures), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this...
I think that in testing we could either do:
await Future.delayed(microseconds: 10);Instead of waiting for deletionsDone.
Or we could change the tests to wait for deleteInstanceFn to have been called N times.
Or we could await deleteInstanceFn in here, with some short timeout like 30s and if it has happened then we log a warning. Nor sure this necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or we could make the agreement that deleteInstanceFn invocations will have been started before we return from scanAndDeleteInstances.
But we won't have awaited the futures from deleteInstanceFn invocations.
That way, if deleteInstanceFn does anything sync, the sync thing will have run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, scanAndDeleteInstances could return ({DeleteInstancesState nextState, Future<void> done}).
I don't like having a type for this... I don't know why.
It feels like we're letting internals escape.
I think we should make the promise that deleteInstanceFn will not be invoked after the Future from scanAndDeleteInstances has been resolved.
We're not promising that Futures from deleteInstanceFn have been resolved, just that we won't make any more calls to deleteInstanceFn.
This requires us to not use scheduleMicrotask(..., but instead do:
Future? f;
try {
// We've promised to never all deleteInstanceFn after the return
// from this function! But have not promised to await Futures
// from deleteInstanceFn in this function!
f = deleteInstanceFn(...)
} catch (e, st) {
_log.severe('Failed to delete $instance', e, st);
}
if (f != null) {
scheduleMicroTask(() async {
try {
await f;
} catch (e, st) {
_log.severe('Failed to delete $instance', e, st);
}
});
}or something like that.
We should declare the invariant in the documentation comment for scanAndDeleteInstances.
135b26b to
c77f148
Compare
…ing tracking state. (dart-lang#9082)
Uh oh!
There was an error while loading. Please reload this page.